﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMS.HelperClasses;
using WHMS.EntityClasses;
using WHMS.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace WMS
{
	public partial class SettingsForm : Form
	{
		public SettingsForm()
		{
			InitializeComponent();

			var currencyForm = new DataMngrFormBase<CurrencyEntity>(_currencies, dataGridView1, bindingSource1, SaveBtn, SaveResult, DeleteResult, null);
			currencyForm.SetMandatoryFields(new List<int>() {0, 1 });

			var itemUnitForm = new DataMngrFormBase<UnitEntity>(_itemUnits, dataGridView2, bindingSource2, SaveBtn2, SaveResult2, DeleteResult2, null);
			itemUnitForm.SetMandatoryFields(new List<int>() { 0, 1 });

			var unitTypeForm = new DataMngrFormBase<UnitTypeEntity>(_unitTypes, dataGridView3, bindingSource3, SaveBtn3, SaveResult3, DeleteResult3, null);
			unitTypeForm.SetMandatoryFields(new List<int>() { 0, 1 });

			var shelfTypeForm = new DataMngrFormBase<ShelfTypeEntity>(_shelfTypes, dataGridView4, bindingSource4, SaveBtn4, SaveResult4, DeleteResult4, null);
			shelfTypeForm.SetMandatoryFields(new List<int>() { 0, 1 });

			var depositTypeForm = new DataMngrFormBase<DepositTypeEntity>(_additionTypes, dataGridView5, bindingSource5, SaveBtn5, SaveResult5, DeleteResult5, null);
			depositTypeForm.SetMandatoryFields(new List<int>() { 0, 1 });

			var withdrawTypeForm = new DataMngrFormBase<WithdrawalTypeEntity>(_removalTypes, dataGridView6, bindingSource6, SaveBtn6, SaveResult6, DeleteResult6, null);
			withdrawTypeForm.SetMandatoryFields(new List<int>() { 0, 1 });

			var inspectionStatusForm = new DataMngrFormBase<InspectionTypeEntity>(_inspectionStatus, dataGridView7, bindingSource7, SaveBtn7, SaveResult7, DeleteResult7, null);
			inspectionStatusForm.SetMandatoryFields(new List<int>() { 0, 1 });

			var unitConversionForm = new DataMngrFormBase<UnitConverterEntity>(_unitConverters, dataGridView8, bindingSource8, SaveBtn8, SaveResult8, DeleteResult8, null);
			unitConversionForm.SetMandatoryFields(new List<int>() { 0, 1, 2 });
			unitConversionForm.SetNumericFields(new List<int>() { 1 });
			unitConversionForm.SetDecimalPlaces(4);

            var withdrawPartyForm = new DataMngrFormBase<WithdrawzPartyEntity>(_withdrawParty, dataGridView9, bindingSource9, SaveBtn9, SaveResult9, DeleteResult9, null);
            withdrawPartyForm.SetMandatoryFields(new List<int>() { 0, 1 });

	

		}

		private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
		{
			var columnIndex = (int)(((System.Windows.Forms.DataGridView)(sender)).CurrentCell.ColumnIndex);

			e.Control.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(this.TextboxNumeric_KeyPress);
			if (columnIndex == 1)
			{
				e.Control.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextboxNumeric_KeyPress);
			}

		}

		private void TextboxNumeric_KeyPress(object sender, KeyPressEventArgs e)
		{
			bool valid = true;

			if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 8)
			{
				valid = false;
			}

			e.Handled = valid;
		}
	}
}
